package com.bike.controller.information;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.bike.controller.BaseController;
import com.bike.entity.HhVersion; 
import com.bike.util.PageData;
import com.bike.service.impl.HhVersionServiceImpl;

 
@Controller
@RequestMapping(value="/hhVersion")
public class HhVersionController extends BaseController {
	
		@Autowired
		private HhVersionServiceImpl  hhVersionService;
	
		/**
		 * 跳转到列表页面
		 */
		@RequestMapping("toList")
		public String toList(){
			return "/information/version/hhVersion_list";
		}
		/**
		 * 列表查询(或根据条件)
		 */
		@RequestMapping("list")
		@ResponseBody
		public PageData list(HttpServletRequest request,Model model){
			PageData pd=PageData.getPageDataByPage(request);
			return hhVersionService.selectHhVersionList(pd);
		}
		/**
		 * 列表查询(或根据条件)
		 */
		@RequestMapping("listAll")
		@ResponseBody
		public PageData listAll(HttpServletRequest request,Model model){
			PageData pd=PageData.getPageDataByPage(request);
			return hhVersionService.selectHhVersionList(pd);
		}
		/**
		 * 跳转到编辑页面（新增和修改）
		 */
		@RequestMapping("toEdit")
		public String toEdit(HttpServletRequest request,Model model){
			PageData pd=PageData.getPageDataByPage(request);
			if(pd.getLong("itemId")>0){
				model.addAttribute("pd", hhVersionService.selectByHhVersionId(pd.getLong("itemId")));
			} 
			return "/information/version/hhVersion_edit";
		}
		/**
		 * 搜素
		 * @param request
		 * @param model
		 * @return
		 */
		@RequestMapping("toSearch")
		public String toSearch(HttpServletRequest request,Model model){
			PageData pd=PageData.getPageDataByPage(request);
			model.addAttribute("pd", pd);
			return "/information/version/hhVersion_search";
		}
		/**
		 * 新增和修改 
		 */
		@RequestMapping("save")
		@ResponseBody
		 public Map<String,Object> save(HttpServletRequest request,HhVersion hhVersion){
			try {
				PageData pd=PageData.getPageDataByPage(request);
				hhVersionService.saveOrUpdate(pd,hhVersion);
				return getSuccessMap();
			} catch (Exception e) {
				e.printStackTrace();
			}
			return getErrorMap("失败");
		 }
		/**
		 * 删除
		 */
	 	@RequestMapping("delete")
		@ResponseBody
		 public Map<String,Object> delete(HttpServletRequest request){
			try {
				PageData pd=PageData.getPageDataByPage(request);
				if(pd.getLong("itemId")>0){
					hhVersionService.deleteHhVersionById(pd.getLong("itemId"));
					return getSuccessMap();
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
			return getErrorMap("失败");
		}
}
